package com.liliudong.rommath.biz.sys.entity;

import com.liliudong.rommath.biz.sys.param.SysRoleAddParam;
import com.liliudong.rommath.biz.sys.param.SysRoleModifyParam;
import com.liliudong.rommath.common.base.IdBaseEntity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.EnumValue;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 系统角色 实体类。
 *
 * @author liudong.li
 * @since 1.0.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Table(value = "sys_role")
public class SysRole extends IdBaseEntity {

    /**
     * 角色名称
     */
    @Column(value = "name")
    private String name;

    /**
     * 数据权限类型 1仅本人 2本部门 3本部门及以下 4全部数据
     */
    @Column(value = "data_scope")
    private DataScope dataScope;

    /**
     * 角色编码
     */
    @Column(value = "code")
    private String code;

    /**
     * 描述
     */
    @Column(value = "description")
    private String description;

    public static SysRole of(SysRoleAddParam param) {
        SysRole sysRole = new SysRole();
        sysRole.setName(param.getName());
        sysRole.setDataScope(param.getDataScope());
        sysRole.setCode(param.getCode());
        sysRole.setDescription(param.getDescription());
        return sysRole;
    }

    public static SysRole of(SysRoleModifyParam param) {
        SysRole sysRole = new SysRole();
        sysRole.setId(param.getId());
        sysRole.setName(param.getName());
        sysRole.setDataScope(param.getDataScope());
        sysRole.setCode(param.getCode());
        sysRole.setDescription(param.getDescription());
        return sysRole;
    }

    /**
     * 数据权限枚举
     *
     * @author ldli5
     * @classname DataScopeEnum
     * @date 2024/6/19-9:46
     */
    @RequiredArgsConstructor
    @Getter
    public enum DataScope {
        // 	数据权限类型 1仅本人 2本部门 3本部门及以下 4全部数据
        SELF(1, "仅本人"),
        DEPARTMENT(2, "本部门"),
        DEPARTMENT_AND_SUBORDINATE(3, "本部门及以下"),
        ALL(4, "全部数据");

        @EnumValue
        private final Integer code;
        private final String desc;

    }
}
